package com.own.business.question.entity.vo;

import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.own.business.question.common.base.ReplyEnvironment;
import com.own.business.question.common.handler.ReplyEnvironmentHandler;
import com.own.business.question.common.serializer.ReplyEnvironmentSerializer;
import com.own.business.question.entity.po.PracticeMistake;
import com.own.component.common.base.entity.vo.BaseVo;
import com.own.constant.ConstantBeanSuffix;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

/**
 * PracticeMistakeVo
 *
 * @author chenxueli
 * @date 2021/05/14 15:49:28
 */
@Schema(description = "练习错题表" + ConstantBeanSuffix.VO)
@Getter
@Setter
@ToString
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
public class PracticeMistakeVo extends BaseVo<PracticeMistake> {

    @Schema(description = "用户id")
    private Long userId;

    @Schema(description = "流水id")
    private Long historyId;

    @Schema(description = "题目id")
    private Long questionId;

    @Schema(description = "用户答案")
    private String answer;

    @Schema(description = "作答环境")
    @TableField(typeHandler = ReplyEnvironmentHandler.class)
    @JsonSerialize(using = ReplyEnvironmentSerializer.class)
    private ReplyEnvironment replyEnvironment;

    @Schema(description = "标记状态 0=未记住 1=已记住")
    private Integer status;

    /**
     * 构造方法
     *
     * @param entity 原对象
     */
    public PracticeMistakeVo(@NonNull PracticeMistake entity) {
        super(entity);
        this.userId = entity.getFkUserId();
        this.historyId = entity.getFkHistoryId();
        this.questionId = entity.getFkQuestionId();
        this.answer = entity.getAnswer();
        this.replyEnvironment = entity.getReplyEnvironment();
        this.status = entity.getStatus();
    }

    /**
     * 转po对象
     *
     * @param entity 原
     * @return po对象
     */
    @Override
    public PracticeMistake toPo(PracticeMistake entity) {
        if (entity == null) {
            entity = new PracticeMistake();
        }
        entity.setFkUserId(this.userId);
        entity.setFkHistoryId(this.historyId);
        entity.setFkQuestionId(this.questionId);
        entity.setAnswer(this.answer);
        entity.setReplyEnvironment(this.replyEnvironment);
        entity.setStatus(this.status);
        return super.toPo(entity);
    }

}
